package bc.controller;

import bc.model.Cards;

import haxe.rtti.Infos;

class CardsLayoutComputer implements Infos
{
	@Inject
	public var cards : Cards;
	
	public function new()
	{
	}
	
	public function computeInitialSetup()
	{
		var selectionOffset = -cards.selected.index * (cards.cardWidth + cards.margin);
		
		for(card in cards.all)
		{
			card.moveSetX.current = card.index * (cards.cardWidth + cards.margin) - cards.cardWidth / 2 + selectionOffset + 50;
			card.moveSetX.acceleration = 1.5;
			 
			card.moveSetY.current = -100;
			card.moveSetY.acceleration = 0.5;
			 
			card.moveSetAlpha.current = -card.index / 2;
			card.moveSetAlpha.acceleration = 0.01;
			
			card.moveSetScale.current = 0.75;
			card.moveSetScale.acceleration = 0.002;
		}
	}
	
	public function computeTargets()
	{
		var selectionOffset = -cards.selected.index * (cards.cardWidth + cards.margin);
		
		for(card in cards.all)
		{
			card.moveSetAlpha.to = 1;
			card.moveSetX.to = card.index * (cards.cardWidth + cards.margin) - cards.cardWidth / 2 + selectionOffset;
			if (card == cards.selected)
			{
				card.moveSetScale.to = 1;
				card.moveSetScale.acceleration = 0.002;
				
				card.moveSetY.to = -100;
				card.moveSetAlpha.to = 1;
			}
			else
			{
				card.moveSetScale.to = 0.75;
				card.moveSetScale.acceleration = 0.0015;
				
				card.moveSetY.to = -100;
				card.moveSetAlpha.to = 0.5;
			}
		}
	}
	
	public function move()
	{
		for(card in cards.all)
		{
			card.moveSetScale.move();
			card.moveSetAlpha.move();
			card.moveSetX.move();
			card.moveSetY.move();
		}
	}
}
